void setup() {
  Serial.begin(9600);
  DDRB |= _BV(5);
  DDRC|=_BV(0);//dat
  DDRC|=_BV(1);//clk
  
  PORTC=0;//dat
}

void send(uint8_t cmd, uint8_t dat){
  
  delay(1); PORTC=                  1 | 2;//1
  delay(1); PORTC=((cmd >> 7) & 0x01) | 0;
  delay(1); PORTC=((cmd >> 6) & 0x01) | 2;
  delay(1); PORTC=((cmd >> 5) & 0x01) | 0;
  delay(1); PORTC=((cmd >> 4) & 0x01) | 2;
  delay(1); PORTC=((cmd >> 3) & 0x01) | 0;
  delay(1); PORTC=((cmd >> 2) & 0x01) | 2;
  delay(1); PORTC=((cmd >> 1) & 0x01) | 0;
  delay(1); PORTC=((cmd >> 0) & 0x01) | 2;
  delay(1); PORTC=                  0 | 0;
  delay(1);
  
  delay(1); PORTC=                  1 | 2;//1
  delay(1); PORTC=((dat >> 7) & 0x01) | 0;
  delay(1); PORTC=((dat >> 6) & 0x01) | 2;
  delay(1); PORTC=((dat >> 5) & 0x01) | 0;
  delay(1); PORTC=((dat >> 4) & 0x01) | 2;
  delay(1); PORTC=((dat >> 3) & 0x01) | 0;
  delay(1); PORTC=((dat >> 2) & 0x01) | 2;
  delay(1); PORTC=((dat >> 1) & 0x01) | 0;
  delay(1); PORTC=((dat >> 0) & 0x01) | 2;
  delay(1); PORTC=                  0 | 0;
  delay(1);

}

// the loop routine runs over and over again forever:
void loop() {
  int val = Serial.parseInt();
  
  if(val!=0){
    
	//public byte CMD_START = 1;/* START */
	//public byte CMD_NOSTART = 2;/* START off */
	//public byte CMD_SETPWRSIMP = 3;/* set power simple */
	//public byte CMD_PITCH = 4;/* PITCH */

    if(val==1000){
      send(1,0);
    }else if(val==2000){
      send(2,0);
    }else{
      send(3,val);
    }
    
  }
}



